package P1线性结构.LeetCode双指针;

import P1线性结构.LinkedList;

public class LeetCode27 {
    public static void main(String[] args) {
        int[] arr = {2, 0, 1, 0, 3, 0, 4};
        int key = 0;
        LinkedList<Integer> queue = new LinkedList<>();
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] != key) {
                queue.offer(arr[i]);
            }
        }
        System.out.println(queue.size());
        System.out.println(queue);
    }

    public int removeElement(int[] nums, int val) {
        int j = -1; // [0,j] 存放结果的区间
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != val) {
                j++;
                nums[j] = nums[i];
            }
        }
        return j + 1;
    }
}
